let search = (function(){
    let newData =[]
    function render(data = []){
        newData = [...newData, ...data]
        console.log(newData);

        let page = ""

        newData.forEach(item =>{
            item.img = item.img.replace('images','./assets/images');
            console.log(item.img);
            page +=`
            
            <div class="nv-con-col">
                    <a href="../pages/${item.titlehref}">
                        ${item.img}
                    </a>
                    <p>
                        ${item.name}
                    </p>
                </div>
            `
        })
        $('.row').html(page)
        // 点击更多 多显示一行
        // console.log($('#info>.nv-con-col'));
        $('.nv-con-col').eq(7).click(function (e) {

            e.preventDefault();
      
          })
        $('.nv-con-col').eq(7).click(function () {
            console.log('1');
            $('.nv-con-col').eq(7).nextAll().slideToggle();
        })
    }
    $.ajax({
        url:'http://chst.vip:1234/api/getindexmenu',
        catch:true    
    })
    .then(res=>{
        render(res.result)
        console.log(res);
    })
})()

//商品请求  渲染页面
let product = (function(){
    let newData = [] //接受请求到的数据
    function render(data =[]){
        newData = [...data, ...newData]
        console.log(newData);

          
        $('.info').html(page)
        // 点击事件
        $('.info').on('click','li',function(){
            let proid = $(this).attr('proid');
            // console.log(proid);
            location.href = `../pages/zhekou.html?productid=${proid}`
        })
    }
    let uu = document.querySelector('ul')
    //1.发起请求获取列表数据

    //2.根据列表数据展示列表内容

    //3.需要将商品的productId绑定到元素上

    //4.点击元素进行跳转,跳到detail页面 并且要携带productId

    let el = ""//设置为空
    fetch('http://chst.vip:1234/api/getmoneyctrl')
    .then(body=>body.json())
    .then(res=>{
        // console.log(res);
        res.result.forEach(item=>{
            // console.log(item);
            let regExp = /(?<=imgurl=)[^'"]*/;
            let r = item.productImg2.match(regExp);
            el+=` <li proid="${item.productId}">

            <img src=${r[0]} height="100" alt="">
            

             <a class="clearfix">
                 <div class="img fl">
                 <b>${item.productName}</b>

                     
                </div>
                <div class="infoR">
                            <div class="title">
                                <h4>${item.productName}
                                    <span>${item.productPinkage}</span>
                                </h4>
                            </div>
                            <div class="other">
                                <span class="mall fl">${item.productFrom}|${item.productTime}</span>
 
                                <em class="fr">
                                    <i class="iconfont icon-xiaoxi "></i>
                                    <span> ${item.productComCount}</span>
                                </em>
 
                            </div>
            
                        </div>
             </a>
             </li>`
         })
         uu.innerHTML = el;
        })
        $('ul').on('click','li',function(){
            // console.log(this);
            let proid = $(this).attr("proid")
            // console.log($('productid'));?
            location.href = `../pages/zhekou.html?productid=${proid}`
            console.log( location.href = `../zhekou.html?productid=${productid}`)
        })

})()
